package com.umgsai.thread.thread63;

import java.sql.Connection;
import java.sql.DriverManager;

public class MyObject {
	public enum MyEnumSingleton{
		connectionFactory;
		private Connection connection;
		private MyEnumSingleton(){
			try {
				System.out.println("创建MyObject对象");
				String url = "jdbc:mysql://127.0.0.1:3306/test";
				String user = "root"; 
		        String password = "";
		        String driver = "com.mysql.jdbc.Driver";
		        Class.forName(driver);
		        connection = DriverManager.getConnection(url, user, password);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		public Connection getConnection() {
			return connection;
		}	
	}
	public static Connection getConnection() {
		return MyEnumSingleton.connectionFactory.getConnection();
	}
}
